﻿#region File and License Information
/*
<File>
	<License>
		Copyright © 2009 - 2017, Daniel Vaughan. All rights reserved.
		This file is part of Calcium (http://calciumsdk.net), 
		which is released under the MIT License.
		See file /Documentation/License.txt for details.
	</License>
	<CreationDate>2009-10-14 11:58:42Z</CreationDate>
</File>
*/
#endregion

using Microsoft.Practices.ServiceLocation;

namespace Outcoder.InversionOfControl
{
	public static class ServiceLocatorExtensions
	{
#if !USE_DEPRECATED_DEPENDCY_API
		public static void RegisterInstance<TService>(this IServiceLocator serviceLocator, TService service)
		{
			var registrar = Dependency.Resolve<IDependencyRegistrar>();
			registrar.Register<TService>(service);
		}

		public static void RegisterType<TFrom, TTo>(this IServiceLocator serviceLocator) where TTo : TFrom
		{
			var registrar = Dependency.Resolve<IDependencyRegistrar>();
			registrar.Register<TFrom, TTo>();
		}
#else
		public static void RegisterInstance<TService>(this IServiceLocator serviceLocator, TService service)
		{
			var registrar = ServiceLocatorSingleton.Instance.GetInstance<IDependencyRegistrar>();
			registrar.RegisterInstance<TService>(service);
		}

		public static void RegisterType<TFrom, TTo>(this IServiceLocator serviceLocator) where TTo : TFrom
		{
			var registrar = ServiceLocatorSingleton.Instance.GetInstance<IDependencyRegistrar>();
			registrar.RegisterType<TFrom, TTo>();
		}
#endif
	}
}
